#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    int rob(vector<int>& nums) {
        if (nums.size() < 1) return 0;
        if (nums.size() == 1) return nums[0];
        vector<vector<int>>dp(nums.size());
        for (int i = 0; i < dp.size(); ++i) {
            dp[i].resize(4);
        }
        for (int i = 0; i < nums.size(); ++i) {
            if (i == 0) {
                dp[i][0]= dp[i][1]=dp[i][2] = 0;
                dp[i][3] = nums[i];
            }
            else {
                dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
                dp[i][1] = dp[i - 1][0] + nums[i];
                dp[i][2] = max(dp[i - 1][2], dp[i - 1][3]);
                dp[i][3] = dp[i - 1][2] + nums[i];
            }
        }
        return max(max(dp.back()[0], dp.back()[2]), dp.back()[1]);

    }
};

//int main() {
//    Solution sol;
//    vector<int>vec = { 2,3,2 };
//    sol.rob(vec);
//}